unit Form_Main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  System.Net.HttpClient, System.Net.URLClient, System.Net.HttpClientComponent,
  NetClient;

type
  TForm1 = class(TForm)
    Btnv_1: TButton;
    Btnv_2: TButton;
    Btnv_3: TButton;
    Btnv_4: TButton;
    NetClient1: TNetHTTPClient;
    Button1: TButton;
    procedure Btnv_1Click(Sender: TObject);
    procedure Btnv_2Click(Sender: TObject);
    procedure Btnv_4Click(Sender: TObject);
    procedure NetClient1RequestError(const Sender: TObject;const AError: string);
    procedure Button1Click(Sender: TObject);
    procedure NetClient1ValidateServerCertificate(const Sender: TObject;const ARequest: TURLRequest; const Certificate: TCertificate;var Accepted: Boolean);
  private
  public
  end;

var
  Form1: TForm1;

implementation

uses
  Class_KzUtils,Class_User,Helpr_UniEngine,NetEngine,Class_KzDebug;

{$R *.dfm}

procedure TForm1.Btnv_1Click(Sender: TObject);
var
  ss: TStringStream;
begin
  ss := TStringStream.Create('', TEncoding.UTF8);
  ss.Clear;
  //?whobuild=1001&userindx=1001
  ShowMessage(NetClient1.Post('http://192.168.0.5:9002/tuser/selectdb',ss).ContentAsString);
  self.Caption:=ss.DataString;
end;

procedure TForm1.Btnv_2Click(Sender: TObject);
var
  ss:TStringList;
  sm:TStringStream;
  cUser:TUSER;

  Return:IHTTPResponse;
begin
  ss := TStringList.Create;
  ss.Clear;

  sm:=TStringStream.Create;

  cUser:=TUSER.Create;
  cUser.USERCODE:='XXXXXXXXX';
  cUser.USERNAME:='YYYYYYYYY';
  cUser.WCONTACT:='ZZZZZZZZZ';
  //#ss.Add(Format('params=%S',[cUser.ToJSON]));

  //#NetClient1.ContentType:='application/x-www-form-urlencoded';
  //#NetClient1.Accept:='text/html, application/xhtml+xml, */*';
  //#NetClient1.AcceptEncoding:='UTF-8';

  Return:=NetClient1.Post('http://192.168.0.5:9002/tping',sm);
  if Return<>nil then
  begin
    ShowMessage(Return.ContentAsString);
  end;
end;

procedure TForm1.Btnv_4Click(Sender: TObject);
var
  cUser:TUSER;
  cList:TCollection;
  Result:TNetClientResult;
begin
  cUser:=TUSER.Create;
  cUser.USERCODE:='XXXXXXXXX';
  cUser.USERNAME:='YYYYYYYYY';
  cUser.WCONTACT:='ZZZZZZZZZ';

  NetClientEx.Initialize('192.168.0.5','9002',False,True);
  //#Result:=NetClientEx.Post('/tping',['params',cUser.ToJSON]);
  Result:=NetClientEx.Post('/tuser/enrolldb',['params',cUser.ToJSON()]);
  case Result of
    ncrNull:;
    ncrEror:
    begin
      ShowMessageFmt('%S',[NetClientEx.Error]);
    end;
    ncrFailure:
    begin
      ShowMessageFmt('failure:%S',[NetClientEx.Error]);
      KzDebug.FileFmt('%S:%S',[self.ClassName,NetClientEx.Error]);
    end;
    ncrSuccess:
    begin
      cList:=TCollection.Create(TUSER);
      TUSER.InJSON(NetClientEx.Value,'LISTDATA',cList);
      ShowMessageFmt('%D',[cList.Count]);
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TKzUtils.Explore;
end;

procedure TForm1.NetClient1RequestError(const Sender: TObject;
  const AError: string);
begin
  ShowMessage(AError);
end;

procedure TForm1.NetClient1ValidateServerCertificate(const Sender: TObject;
  const ARequest: TURLRequest; const Certificate: TCertificate;
  var Accepted: Boolean);
begin
  Accepted:=True;
end;

end.

  Accepted:=True;

  ShowMessage(Certificate.Issuer);
  ShowMessage(FormatDateTime('YYYY-MM-DD',Certificate.Expiry));
  ShowMessage(FormatDateTime('YYYY-MM-DD',Certificate.Start));
  ShowMessage(Certificate.Subject);
  ShowMessage(Certificate.ProtocolName);
  ShowMessage(Certificate.AlgEncryption);
  ShowMessageFmt('%D',[Certificate.KeySize]);
